package com.bvblogic.android;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PromosListArrayAdapter extends ArrayAdapter<Promo> {

	private Context context;
	private int layoutResource;
//	private int titleResource;
	private List<Promo> promosList;
	
	
	public PromosListArrayAdapter(Context context, int textViewResourceId,
			List<Promo> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
//		this.titleResource = textViewResourceId;
		this.promosList = objects;
		layoutResource = R.layout.restaurant_details_promo_list_item;
	}

	public PromosListArrayAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
		this.context = context;
//		this.titleResource = textViewResourceId;
		this.promosList = new ArrayList<Promo>();
		layoutResource = R.layout.restaurant_details_promo_list_item;
	}

	public PromosListArrayAdapter(Context context, int resource,
			int textViewResourceId, List<Promo> objects) {
		super(context, resource, textViewResourceId, objects);
		this.context = context;
		this.layoutResource = resource;
//		this.titleResource = textViewResourceId;
		this.promosList = objects;
	}

	@Override
	public void add(Promo object) {
		promosList.add(object);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return promosList.size();
	}
	
	@Override
	public Promo getItem(int position) {
		// TODO Auto-generated method stub
		return promosList.get(position);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			view = inflater.inflate(layoutResource, parent, false);
		}
		ImageView img = (ImageView) view.findViewById(R.id.restaurant_avatar);
		TextView title = (TextView) view.findViewById(R.id.promo_name);
		TextView descr = (TextView) view.findViewById(R.id.promo_description);
		Promo promo = promosList.get(position);
//		img.setImageResource(promo.getImageRes());
		title.setText(promo.getTitle());
		descr.setText(promo.getDescription());
		
		return view;
	}
	
	

}
